<?php

namespace App\Http\Services;

use App\Constants\ResponseArray;
use Illuminate\Http\Request;

class UploadService extends BaseService {

    const OSS_HOST = 'https://cheng-yue.oss-cn-chengdu.aliyuncs.com';
    /**
     * 上传单张图片
     * @param Request $request
     * @return array
     */
    public static function uploadImage(Request $request)
    {
        $guessExtension = $request->file('file')->guessExtension();
        $folder = $request->input('folder','image');

        $ossFilePath = $request->file('file')->storeAs($folder, uniqid().'.'.$guessExtension  ,'oss');

        if (!$ossFilePath)
        {
            return ResponseArray::abortMessage('上传失败.');
        }

        $array = [
            'url' => self::OSS_HOST . '/' . $ossFilePath,
            'folder' => $folder,
        ];

        return ResponseArray::response($array,'上传成功.');
    }



}